﻿using System;
using System.Linq;
using System.Collections.Generic;
using DAL;
using BLL;
using Common;
using System.Web.Mvc;
using App.Models;

namespace App.Controllers
{
    /// <summary>
    /// 部门树形结构
    /// </summary>
    public class SysDepartmentTreeController : BaseController
    {
        public ActionResult Index()
        {
            return View();
        }

        [HttpPost]
        public ActionResult GetAllMetadata()
        {
            SysDepartmentBLL m_BLL = new SysDepartmentBLL();
            List<SysDepartmentSef> collection = m_BLL.GetAllMetadata();
            if (collection != null && collection.Count > 0)
            {
                Metadata metadata = new Metadata();
                metadata.rows = collection;
                return Json(metadata);
            }
            return Json("");
        }
        public ActionResult GetTree()
        {
            List<SystemTree> listSystemTree = new List<SystemTree>();
            using (SysDepartmentBLL db = new SysDepartmentBLL())
            {
                SysDepartmentTreeNodeCollection tree = new SysDepartmentTreeNodeCollection();
                var trees = db.GetAll().OrderBy(o => o.Sort);
                if (trees != null)
                {
                    tree.Bind(trees, null, ref listSystemTree);
                }
            }
            return Json(listSystemTree, JsonRequestBehavior.AllowGet);
        }
    }
}

